import { http } from '@/utils/request'
// 获取频道数据
export const getChannelsApi = () => http('/channels', 'get')
/**
 * 获取文章列表
 * @param {Object} params {status:1,channel_id:'',begin_pubdate:'',end_pubdate:'',page:1,per_page:10}
 * @returns
 */
export const getArticleListApi = (params) => http('/mp/articles', 'get', params)

/**
 * 发表文章/存草稿
 * @param  {Boolean} draft 是否存草稿，true代表存草稿
 * @param {Object} data  {title:'',content:'',channel_id:1,cover:{ type:1,images:[]}}
 * @returns
 */
export const addArticleApi = (data, draft = false) =>
  http(`/mp/articles?draft=${draft}`, 'post', data)

// 删除文章
export const deleteArticleApi = (id) => http(`/mp/articles/${id}`, 'delete')

// 获取文章详情
export const getArticleDetailApi = (id) => http(`/mp/articles/${id}`, 'get')

/**
 * 编辑文章
 * @param  {Boolean} draft 是否存草稿，true代表存草稿
 * @param {Object} data  {title:'',content:'',channel_id:1,cover:{ type:1,images:[]}}
 * @returns
 */
export const editArticleApi = (data, id, draft = false) =>
  http(`/mp/articles/${id}?draft=${draft}`, 'put', data)
